package com.bsg.upm.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bsg.upm.constant.DictTypeConstants;
import com.bsg.upm.dto.SelectDto;
import com.bsg.upm.service.SelectService;

/**
 * SELECT控件内容获取
 * 
 * @author HCK
 *
 */
@Controller
@RequestMapping("v1.0/selections")
public class SelectController {

	@Resource
	private SelectService selectService;

	/**
	 * 【用户角色】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "roles", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listUserRoles() {
		return selectService.listUserRoleName();
	}

	/**
	 * 【用户组】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "groups", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listUserGroups() {
		return selectService.listUserGroupName();
	}

	/**
	 * 【站点】
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return SELECT列表
	 */
	@RequestMapping(value = "sites", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listSite() {
		return selectService.listSiteName();
	}

	/**
	 * 【备份存储】
	 * 
	 * @param siteId
	 *            所属站点
	 * @param enabledStr
	 *            可用
	 * @return
	 */
	@RequestMapping(value = "backup_storages", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listBackupStorage(@RequestParam(value = "site", required = true) String siteId,
			@RequestParam(value = "enabled", required = false) String enabledStr) {
		Boolean enabled = null;
		if (enabledStr != null) {
			if ("1".equals(enabledStr)) {
				enabled = true;
			} else if ("0".equals(enabledStr)) {
				enabled = false;
			} else {
				return new ArrayList<>();
			}
		}
		return selectService.listBackupStorageName(siteId, enabled);
	}

	/**
	 * 【区域】
	 * 
	 * @param siteId
	 *            所属站点
	 * @param enabledStr
	 *            可用
	 * @return SELECT列表
	 */
	@RequestMapping(value = "areas", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listAreaName(@RequestParam(value = "site", required = true) String siteId,
			@RequestParam(value = "enabled", required = false) String enabledStr) {
		Boolean enabled = null;
		if (enabledStr != null) {
			if ("1".equals(enabledStr)) {
				enabled = true;
			} else if ("0".equals(enabledStr)) {
				enabled = false;
			} else {
				return new ArrayList<>();
			}
		}
		return selectService.listAreaName(siteId, enabled);
	}

	/**
	 * 【网段】
	 * 
	 * @param siteId
	 *            所属站点
	 * @param enabledStr
	 *            可用
	 * @return SELECT列表
	 */
	@RequestMapping(value = "networkings/unused", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listNetworkingName(@RequestParam(value = "site", required = true) String siteId,
			@RequestParam(value = "enabled", required = false) String enabledStr) {
		Boolean enabled = null;
		if (enabledStr != null) {
			if ("1".equals(enabledStr)) {
				enabled = true;
			} else if ("0".equals(enabledStr)) {
				enabled = false;
			} else {
				return new ArrayList<>();
			}
		}
		return selectService.listUnusedNetworkingName(siteId, enabled);
	}

	/**
	 * 【集群】
	 * 
	 * @param areaId
	 *            所属集群
	 * @param enabledStr
	 *            可用
	 * @return SELECT列表
	 */
	@RequestMapping(value = "clusters", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listClusterName(@RequestParam(value = "area", required = true) String areaId,
			@RequestParam(value = "enabled", required = false) String enabledStr) {
		Boolean enabled = null;
		if (enabledStr != null) {
			if ("1".equals(enabledStr)) {
				enabled = true;
			} else if ("0".equals(enabledStr)) {
				enabled = false;
			} else {
				return new ArrayList<>();
			}
		}
		return selectService.listClusterName(areaId, enabled);
	}

	/**
	 * 【主机】
	 * 
	 * @param siteId
	 *            所属站点
	 * @param clusterId
	 *            所属集群
	 * @return SELECT列表
	 */
	@RequestMapping(value = "hosts", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listHostName(@RequestParam(value = "site", required = false) String siteId,
			@RequestParam(value = "cluster", required = false) String clusterId) {
		return selectService.listHostName(siteId, clusterId);
	}

	/**
	 * 【SAN】
	 * 
	 * @param siteId
	 *            所属站点
	 * @return SELECT列表
	 */
	@RequestMapping(value = "sans", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listSanName(@RequestParam(value = "site", required = false) String siteId) {
		return selectService.listSanName(siteId);
	}

	/**
	 * 【软件】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "softwares", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listSoftware() {
		return selectService.listSoftware();
	}

	/**
	 * 【软件主次版本】
	 * 
	 * @param definitionSubServName
	 *            子服务定义名称
	 * @return SELECT列表
	 */
	@RequestMapping(value = "software/major_minor_versions", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listSoftwareMainVersion(
			@RequestParam(value = "software_type", required = true) String definitionSubServName) {
		return selectService.listSoftwareMajorAndMinorVersion(definitionSubServName);
	}

	/**
	 * 【服务类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "serv_types", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listServType() {
		return selectService.listServType();
	}

	// /**
	// * 【服务】
	// *
	// * @param paramMap
	// * 请求参数
	// * @return SELECT列表
	// */
	// @RequestMapping(value = "servs", method = RequestMethod.GET)
	// @ResponseBody
	// public List<SelectDto> listServName(@RequestParam(value = "site",
	// required = true) String siteId,
	// @RequestParam(value = "definition_serv", required = true) String
	// definitionServId) {
	// return selectService.listServName(siteId, definitionServId);
	// }

	/**
	 * 【子服务架构】
	 * 
	 * @param definitionServCode
	 *            服务定义代码
	 * @param definitionSubServName
	 *            子服务定义名
	 * @return SELECT列表
	 */
	@RequestMapping(value = "archs", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listArch(@RequestParam(value = "serv_type", required = true) String definitionServCode,
			@RequestParam(value = "subserv_type", required = true) String definitionSubServName) {
		return selectService.listArchName(definitionServCode, definitionSubServName);
	}

	/**
	 * 【接入点数量】
	 * 
	 * @param definitionServCode
	 *            服务定义代码
	 * @param definitionSubServName
	 *            子服务定义名
	 * @return SELECT列表
	 */
	@RequestMapping(value = "aps", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listAccessPoint(
			@RequestParam(value = "serv_type", required = true) String definitionServCode,
			@RequestParam(value = "subserv_type", required = true) String definitionSubServName) {
		return selectService.listAccessPointNum(definitionServCode, definitionSubServName);
	}

	/**
	 * 【子服务规模】
	 * 
	 * @param definitionServCode
	 *            服务定义代码
	 * @param definitionSubServName
	 *            子服务定义名
	 * @return SELECT列表
	 */
	@RequestMapping(value = "scales", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listScale(@RequestParam(value = "serv_type", required = true) String definitionServCode,
			@RequestParam(value = "subserv_type", required = true) String definitionSubServName) {
		return selectService.listScaleName(definitionServCode, definitionSubServName);
	}

	/**
	 * 【软件版本】
	 * 
	 * @param siteId
	 *            站点编码
	 * @param definitionSubServName
	 *            子服务定义名
	 * @return SELECT列表
	 */
	@RequestMapping(value = "software/versions", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listVersion(@RequestParam(value = "site", required = true) String siteId,
			@RequestParam(value = "software_type", required = true) String definitionSubServName,
			@RequestParam(value = "enabled", required = false) String enabledStr) {
		Boolean enabled = null;
		if (enabledStr != null) {
			if ("1".equals(enabledStr)) {
				enabled = true;
			} else if ("0".equals(enabledStr)) {
				enabled = false;
			} else {
				return new ArrayList<>();
			}
		}
		return selectService.listVersion(siteId, definitionSubServName, enabled);
	}

	/**
	 * 【业务系统】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "business_systems", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listBusinessSystemName() {
		return selectService.listBusinessSystemName();
	}

	/**
	 * 【业务子系统】
	 * 
	 * @param businessSystemId
	 *            业务系统编码
	 * @return SELECT列表
	 */
	@RequestMapping(value = "business_subsystems", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listVersion(
			@RequestParam(value = "business_system", required = true) String businessSystemId) {
		return selectService.listBusinessSubSystemName(businessSystemId);
	}

	/**
	 * 【SAN品牌】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "san_vendors", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listSanVendor() {
		return selectService.listSanVendor();
	}

	/**
	 * 【套餐】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "combos", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listCombo(@RequestParam(value = "serv_type", required = true) String definitionServCode) {
		return selectService.listCombo(definitionServCode);
	}

	/**
	 * 【权限】
	 * 
	 * @param enabledStr
	 *            可用
	 * @return SELECT列表
	 */
	@RequestMapping(value = "privileges", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listPrivilege(@RequestParam(value = "enabled", required = false) String enabledStr) {
		Boolean enabled = null;
		if (enabledStr != null) {
			if ("1".equals(enabledStr)) {
				enabled = true;
			} else if ("0".equals(enabledStr)) {
				enabled = false;
			} else {
				return new ArrayList<>();
			}
		}
		return selectService.listPrivilege(enabled);
	}

	/**
	 * 【地域】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "regions", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listRegion() {
		return selectService.listName(DictTypeConstants.REGION);
	}

	/**
	 * 【备份存储类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "backup_storage_types", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listBackupStorageType() {
		return selectService.listName(DictTypeConstants.BACKUP_STORAGE_TYPE);
	}

	/**
	 * 【存储类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "storage_types", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listStorageType() {
		return selectService.listName(DictTypeConstants.STORAGE_TYPE);
	}

	/**
	 * 【网络带宽】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "network_bandwidth", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listNetworkBandwidth() {
		return selectService.listName(DictTypeConstants.NETWORK_BANDWIDTH);
	}

	/**
	 * 【数据目录类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "data_dir_types", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listdataDirType() {
		return selectService.listName(DictTypeConstants.DATA_DIR_TYPE);
	}

	/**
	 * 【日志目录类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "log_dir_types", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listLogDirType() {
		return selectService.listName(DictTypeConstants.LOG_DIR_TYPE);
	}

	/**
	 * 【数据范围】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "data_scopes", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listDataScope() {
		return selectService.listName(DictTypeConstants.DATA_SCOPE);
	}

	/**
	 * 【备份类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "backup_types", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listBackupType() {
		return selectService.listName(DictTypeConstants.BACKUP_TYPE);
	}

	/**
	 * 【字符集类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "character_sets", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listCharacterSet() {
		return selectService.listName(DictTypeConstants.CHARACTER_SET);
	}

	/**
	 * 【迁移/重建 策略类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "strategy_types", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listStrategyType() {
		return selectService.listName(DictTypeConstants.STRATEGY_TYPE);
	}

	/**
	 * 【用户模式类型】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "user_models", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listUserModel() {
		return selectService.listName(DictTypeConstants.USER_MODEL);
	}

	/**
	 * 【工单状态】
	 * 
	 * @return SELECT列表
	 */
	@RequestMapping(value = "order_status", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listOrderStatus() {
		return selectService.listName(DictTypeConstants.ORDER_STATUS);
	}

	@RequestMapping(value = "monitor_metri_types", method = RequestMethod.GET)
	@ResponseBody
	public List<SelectDto> listMonitorType() {
		return selectService.listMonitorTypeName();
	}

}
